home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / oop_tp55.zip / LIST3_1.PAS < prev    next >
Pascal/Delphi Source File  |  1990-03-08  |  12KB  |  475 lines

  1. { Unit: Tags
  2.  
  3. Utilization notes:
  4.  
  5. 1. If no file name is supplied on the command line, the
  6.    program will print output to the screen.  If a file
  7.    name is supplied, the output will be directed to the
  8.    file.
  9.  
  10. 2. The object 'Quiet' controls program output
  11.    (including the opening and closing of output files.)
  12.    The procedure Quiet.On will turn output off and close
  13.    the output file, if one is specified.  Subsequent calls
  14.    to the procedure Quiet.Off will turn output back on and
  15.    append it to f.  The default status of Quiet is ON.
  16.  
  17. 3. Users wanting to write to a file must first
  18.    make sure Quiet is Off, and direct output to
  19.    the file f, as in the following example.
  20.  
  21.      if Quiet.IsOff then
  22.          writeln( f, 'Put your string here' );
  23.  
  24. 4. Programs using this unit should, at the end of the progam,
  25.    explicitly make a call to Quiet.On 
  26.  
  27. }
  28.  
  29. { Specification for Tags class ***************************
  30.  
  31.   Variables:
  32.             TagNumber : String12;
  33.             Stores a tag number of up to 12 characters.
  34.  
  35.   Procedures:
  36.             .Init(( ATag : String12 );
  37.             ATag is stored in TagNumber.
  38.  
  39.   Descendant object types:
  40.             Digital
  41.             Analog              }
  42.  
  43. { Specification for Digital class ************************
  44.  
  45.   Variables:
  46.             Status : boolean;
  47.             Indicates whether digital object is ON or OFF.
  48.             ON denotes TRUE; OFF, FALSE.
  49.  
  50.   Procedures:
  51.             .Init( ATag : String12; AStatus : boolean );
  52.             ATag is stored in TagNumber; AStatus is stored
  53.             in Status.
  54.  
  55.             .PutStatus( AStatus : boolean );
  56.             Sets Status to AStatus.
  57.  
  58.   Functions:
  59.             .GetStatus : boolean;
  60.             Returns ON or OFF status of object.
  61.             If variable 'Quiet' (boolean) is ON, then
  62.             Status is not printed to screen; otherwise
  63.             the Status and TagNumber are printed to
  64.             the screen.
  65.  
  66.   Descendant object types:
  67.             DInput
  68.             DOutput          }
  69.  
  70. { Specification for Analog class *************************
  71.   Variables:
  72.             Value : Resolution;
  73.             Value must have a value between 0 and 4095.
  74.  
  75.             ZeroVal : real;
  76.             Engineering unit value corresponding to a Value
  77.             of 0.
  78.  
  79.             MaxVal : real;
  80.             Engineering unit value corresponding to a Value
  81.             of 4095.
  82.  
  83.             Slope : real;
  84.             A number calculated from the equation:
  85.    (MaxVal-ZeroVal)/(4095-0).
  86.  
  87.   Procedures:
  88.             .Init(( ATag : String12; AValue : Resolution;
  89.             Min, Max : real );
  90.             Storage as follows:
  91.    ATag -> TagNumber
  92.    AValue -> Value
  93.    Min -> ZeroVal
  94.    Max -> MaxVal
  95.  
  96.             .PutValue( AValue : real );
  97.             Converts AValue engineering units into counts
  98.             (between 0 and 4095) and stores in Value.
  99.  
  100.   Functions:
  101.             .GetValue : real;
  102.             Converts and returns the counts in Value to
  103.             engineering units.
  104.  
  105.   Descendant types:
  106.             None.       }
  107.  
  108. { Specification for DInput class *************************
  109.  
  110.   Variables:
  111.             Setpoint : real;
  112.             Contains a value at which something happens.
  113.  
  114.             Reading : real;
  115.             Contains an number that is compared to the
  116.             setpoint.
  117.  
  118.   Procedures:
  119.             .PutSetpoint( NewSetpoint : real );
  120.             Sets Setpoint to NewSetpoint.
  121.  
  122.             NOTE: .Init procedure is packaged with
  123.      descendant classes.
  124.  
  125.   Descendant object types:
  126.             HiSwitch
  127.             LoSwitch         }
  128.  
  129. { Specification for DOutput class ************************
  130.  
  131.     NO VARIABLES, NO PROCEDURES, NO FUNCTIONS
  132.     (see descendant object type)
  133.  
  134.   Descendant object types:
  135.             Pump        }
  136.  
  137. { Specification for HiSwitch class ************************
  138.  
  139.   Procedures:
  140. .Init(( ATag : string;
  141.         ASetpoint : real;
  142.         AReading : real);
  143. Storage as follows:
  144.   ATag -> TagNumber
  145.   ASetpoint -> Setpoint
  146. The value of AReading is stored in Reading
  147. using the .PutReading method.
  148.  
  149. .PutReading( NewReading : real);
  150. Store NewReading in Reading.  Set Status to
  151. ON if Reading >= Setpoint.
  152.  
  153.   Descendant object types:
  154. None.      }
  155.  
  156. { Specification for LoSwitch class ************************
  157.  
  158.   Procedures:
  159. .Init(( ATag : string;
  160.         ASetpoint : real;
  161.         AReading : real);
  162. Storage as follows:
  163.   ATag -> TagNumber
  164.   ASetpoint -> Setpoint
  165. The value of AReading is stored in Reading
  166. using the .PutReading method.
  167.  
  168. .PutReading( NewReading : real);
  169. Store NewReading in Reading.  Set Status to
  170. ON if Reading <= Setpoint.
  171.  
  172.   Descendant object types:
  173. None.      }
  174.  
  175. { Specification for Pump class **************************
  176.  
  177.   Variables:
  178.             FlowRate : real;
  179.             A number representing gpm flow when pump is
  180.             ON.  NOTE: THIS IS A *VERY* ROUGH APPROXIMATION
  181.             OF PUMP BEHAVIOR!
  182.  
  183.   Procedures:
  184.             .Init( ATag : String12; AStatus : boolean;
  185.       AFlow : real );
  186.             Storage as follows:
  187.   ATag -> TagNumber
  188.   AStatus -> Status
  189.   AFlow -> FlowRate
  190.  
  191.   Functions:
  192.             .Flow : real;
  193.             Returns the value stored in FlowRate.
  194.  
  195.   Descendant object types:
  196.             None.       }
  197.  
  198. unit Tags;
  199.  
  200. interface
  201.  
  202. uses Crt; { for KeyPressed }
  203.  
  204. const
  205.  
  206. ON  = true;
  207. OFF = false;
  208. MinR = 0;       { Minimum number of counts in an analog input }
  209. MaxR = 4095;    { Maximum number of counts in an analog input }
  210.  
  211. var
  212.     f : text;  {predefined file type}
  213.  
  214. type
  215.  
  216. Resolution = 0..4095;  { Range for analog input }
  217. String12 = string[12];
  218.  
  219.  
  220. Tag = object
  221.       TagNumber : String12;
  222.       procedure Init( ATag : String12 );
  223.       end;
  224.  
  225. Digital = object(Tag)
  226.           Status : boolean;
  227.           procedure Init( ATag : String12; AStatus :
  228. boolean );
  229.           procedure PutStatus( AStatus : boolean );
  230.           function GetStatus : boolean;
  231.           end;
  232.  
  233. Analog = object(Tag)
  234.          Value : Resolution;
  235.          ZeroVal : real;
  236.          MaxVal : real;
  237.          Slope  : real;
  238.          procedure Init( ATag : String12; AValue :
  239. Resolution;
  240.             Min, Max : real );
  241.          procedure PutValue( AValue : real );
  242.          function GetValue : real;
  243.          end;
  244.  
  245. DOutput = object(Digital)
  246.           end;
  247.  
  248. Pump = object(DOutput)
  249.        FlowRate : real;
  250.        procedure Init( ATag : String12; AStatus : boolean;
  251.                        AFlow : real );
  252.        function Flow : real;
  253.        end;
  254.  
  255.  
  256. DInput = object(Digital)
  257.             Setpoint  : real;
  258.             Reading   : real;
  259.             procedure PutSetpoint( NewSetpoint : real );
  260.             end;
  261.  
  262. HiSwitch = object(DInput)
  263.            procedure Init( ATag : string;
  264.             ASetpoint : real;
  265.             AReading : real);
  266.            procedure PutReading( NewReading : real );
  267.            end;
  268.  
  269. LoSwitch = object(DInput)
  270.            procedure Init( ATag : string;
  271.             ASetpoint : real;
  272.             AReading : real);
  273.            procedure PutReading( NewReading : real );
  274.            end;
  275.  
  276. FSwitch = object
  277.           State : boolean;
  278.           procedure Init( InitState : boolean );
  279.           procedure On;
  280.           procedure Off;
  281.           function IsOn : boolean;
  282.           function IsOff : boolean;
  283.           end;
  284.  
  285.  
  286. function HtToPSI( Height : real ) : real;
  287.  
  288. function FlowToDeltaHt( Flow : real ) : real;
  289.  
  290. var
  291.    Quiet : FSwitch;
  292.  
  293. implementation
  294.  
  295. procedure Tag.Init( ATag : String12 );
  296. begin
  297.      TagNumber := ATag;
  298. end;
  299.  
  300. procedure Digital.Init( ATag : String12; AStatus : boolean
  301. );
  302. begin
  303.      Tag.Init( ATag );
  304.      Status := AStatus;
  305. end;
  306.  
  307. procedure Digital.PutStatus( AStatus : boolean );
  308. begin
  309.      Status := AStatus;
  310. end;
  311.  
  312. function Digital.GetStatus : boolean;
  313. begin
  314.      if (Status = ON) and (Quiet.IsOff) then
  315.         writeln( f, TagNumber, ' is ON.' )
  316.      else
  317.         if (Quiet.IsOff) then
  318.            writeln( f, TagNumber, ' is OFF.' );
  319.      GetStatus := Status;
  320. end;
  321.  
  322. procedure Pump.Init( ATag : String12; AStatus : boolean;
  323. AFlow : real );
  324. begin
  325.      Digital.Init( ATag, AStatus );
  326.      FlowRate := AFlow;
  327. end;
  328.  
  329. function Pump.Flow : real;
  330. begin
  331.      Flow := FlowRate;
  332. end;
  333.  
  334. procedure Analog.Init( ATag : String12;
  335.           AValue : Resolution;
  336.           Min, Max : real );
  337. begin
  338.      Tag.Init( ATag );
  339.      Value := AValue;
  340.      MaxVal := Max;
  341.      ZeroVal := Min;
  342.      Slope := (Max-Min)/(MaxR-MinR);
  343. end;
  344.  
  345. procedure Analog.PutValue( AValue : real );
  346. begin
  347.      if AValue > MaxVal then
  348.         AVAlue := MaxVal
  349.      else
  350.         if AValue < ZeroVal then
  351.            AValue := ZeroVal;
  352.      Value := Round((AValue - ZeroVal)/Slope);
  353. end;
  354.  
  355. function Analog.GetValue : real;
  356. begin
  357.      GetValue := Slope*Value + ZeroVal;
  358. end;
  359.  
  360. procedure DInput.PutSetpoint( NewSetpoint : real );
  361. begin
  362.      Setpoint := NewSetpoint;
  363. end;
  364.  
  365. procedure LoSwitch.Init( ATag : string;
  366.             ASetpoint : real;
  367.             AReading : real);
  368. begin
  369.      Tag.Init( ATag );
  370.      DInput.PutSetpoint( ASetpoint );
  371.      PutReading( AReading );
  372. end;
  373.  
  374. procedure LoSwitch.PutReading( NewReading : real );
  375. begin
  376.      Reading := NewReading;
  377.      if Reading <= Setpoint then
  378.         Status := true
  379.      else
  380.         Status := false;
  381. end;
  382.  
  383. procedure HiSwitch.Init( ATag : string;
  384.             ASetpoint : real;
  385.             AReading : real);
  386. begin
  387.      Tag.Init( ATag );
  388.      DInput.PutSetpoint( ASetpoint );
  389.      PutReading( AReading );
  390. end;
  391.  
  392. procedure HiSwitch.PutReading( NewReading : real );
  393. begin
  394.      Reading := NewReading;
  395.      if Reading >= Setpoint then
  396.         Status := true
  397.      else
  398.         Status := false;
  399. end;
  400.  
  401. procedure FSwitch.Init( InitState : boolean );
  402. begin
  403.      State := InitState;
  404.      if State = false then  { If we want output}
  405.         Rewrite( f )      { Open file f }
  406.      else
  407.         begin
  408.         Rewrite( f );     { Open file f }
  409.         Close( f );       { and close it }
  410.         end;
  411. end;
  412.  
  413. procedure FSwitch.On;
  414. begin
  415.      if State = false then
  416.         begin
  417.         State := true;
  418.         Close( f );
  419.         end;
  420. end;
  421.  
  422. procedure FSwitch.Off;
  423. begin
  424.      if State = true then
  425.         begin
  426.         State := false;
  427.         Append( f );
  428.         end;
  429. end;
  430.  
  431. function FSwitch.IsOn : boolean;
  432. begin
  433.      if State = true then
  434.         IsOn := true
  435.      else
  436.         IsOn := false;
  437. end;
  438.  
  439. function FSwitch.Isoff : boolean;
  440. begin
  441.      IsOff := not IsOn;
  442. end;
  443.  
  444. { HtToPSI converts a height (of a column of water) into a pressure.
  445.   The math is pretty simple:  A column of water 2.31 feet high exerts
  446.   a force of one pound per square inch at the bottom. }
  447.  
  448. function HtToPSI( Height : real ) : real;
  449. begin
  450.      HtToPSI := Height/2.31;
  451. end;
  452.  
  453. { FlowToDeltaHt converts a flow into (or out of) our system into a
  454.   change in height in the tank.
  455.   The math is as follows:  Divide the flow, in gpm, by 7.48 gal/cu.ft.
  456.   to get the number of cubic feet pumped per minute. Divide this
  457.   number by the volume of 1 vertical foot of the tank, which is
  458.   the radius squared times 'pi' (15*15*3.1416). }
  459.  
  460. function FlowToDeltaHt( Flow : real ) : real;
  461. begin
  462.      FlowToDeltaHt := Flow/(7.48 * 706) ;
  463. end;
  464.  
  465. { initialization code }
  466. begin
  467.  
  468. Assign( f, ParamStr(1) );
  469.  
  470. Quiet.Init(OFF);
  471.  
  472. end.
  473.  
  474. { Listing 3-1 }
  475.